Quarto Basics

Animated Gapminder Data

For a demonstration of plot that we animate to view evolution over time, see Figure 1.

Code
import plotly.express as px
gp = px.data.gapminder()
px.scatter(gp, x="gdpPercap", y="lifeExp", 
           animation_frame="year", animation_group="country",
           size="pop", color="continent", hover_name="country",
           log_x=True, size_max=55, range_x=[100,100000], range_y=[25,90])
Figure 1: Animation of the Gapminder Dataset
Code
import altair as alt
import math

my_si = alt.selection_interval()

gp['gdpPercapLog'] = gp['gdpPercap'].apply(lambda x: math.log(x))

points = alt.Chart(gp).mark_point().encode(
    alt.X('gdpPercapLog',scale=alt.Scale(domain=[4, 12])),
    alt.Y('lifeExp',scale=alt.Scale(domain=[20, 90]))
).add_params(
    my_si
)

barsX = alt.Chart(gp).mark_bar().encode(
    alt.X('gdpPercapLog',bin=True,scale=alt.Scale(domain=[4, 12])),
    y='count()'
).transform_filter(
    my_si
)

barsY = alt.Chart(gp).mark_bar().encode(
    alt.Y('lifeExp',bin=True,scale=alt.Scale(domain=[20, 90])),
    x='count()'
).transform_filter(
    my_si
)

chart = alt.vconcat(barsX,
            alt.hconcat(points,barsY))

chart.show()
Figure 2: Interactive Views of Gapminder Dataset Variation